package com.yuanjin.activity;

import java.util.Vector;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;

import com.yuanjin.R;
import com.yuanjin.util.MyAdaper;
import com.yuanjin.util.MyAdaper.FriendsItem;
import com.yuanjin.util.YuanJin_Application;

public class FriendsListActivity extends Activity implements OnItemClickListener {
	private ListView listview;
	Vector<FriendsItem> list = new Vector<FriendsItem>();
	Vector<FriendsItem> list2 = new Vector<FriendsItem>();

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.friendslist);
		listview = (ListView) findViewById(R.id.friendsList);

		dataInit();
		MyAdaper ma = null;
		ma = new MyAdaper(list, this.getApplicationContext());
		listview.setAdapter(ma);
		// 对listview对象进行监听，当点击子项目时触发
		listview.setOnItemClickListener(this);
	}

	public void dataInit() {
		// MyData类中保存了返回的数据的总数receiveData_Sum和数据存储的字符串receiveData
		YuanJin_Application md = (YuanJin_Application) getApplication();
		// 将字符串转换为数组--提取用户数据分别存储
		String[] dataArray = md.getReceiveData().split("###");
		for (int i = 0; i < md.getReceiveData_Sum(); i++) {
			Log.e("数组内容显示", dataArray[i]);

			// 在静态类中无法调用动态类，所以FriendsItem（）类要设置为静态
			FriendsItem friendsItem = new FriendsItem();
			friendsItem.name = dataArray[i];
			// Log.e("postout", "qianmian。。。"+Integer.toString(index));
			friendsItem.picture = new ImageView(this.getBaseContext());
			friendsItem.picture.setImageResource(R.drawable.yuanjin);
			// Log.e("postout", "来了。。。"+Integer.toString(index));
			list.addElement(friendsItem);

		}

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		Log.e("onclick", "进入点击事件了");
		FriendsItem map = (FriendsItem) listview.getItemAtPosition(position);
		String title = map.name;
		Intent intent=new Intent(this,ChatArea3.class);
		intent.putExtra("friendsname", title);
		startActivity(intent);
		
		//Toast.makeText(FriendsList.this, title, Toast.LENGTH_LONG).show();
		//Log.e("itemclick", title + "看着里");

	}

}